home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb-4.5 / dist / gdb / inftarg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-29  |  5.9 KB  |  219 lines

  1. /* Subroutines for handling an "inferior" (child) process as a target
  2.    for debugging, in GDB.
  3.    Copyright 1990, 1991 Free Software Foundation, Inc.
  4.    Contributed by Cygnus Support.
  5.  
  6. This file is part of GDB.
  7.  
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program; if not, write to the Free Software
  20. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  21.  
  22. #include "defs.h"
  23. #include "frame.h"  /* required by inferior.h */
  24. #include "inferior.h"
  25. #include "target.h"
  26. #include "wait.h"
  27. #include "gdbcore.h"
  28. #include "ieee-float.h"        /* Required by REGISTER_CONVERT_TO_XXX */
  29.  
  30. static void
  31. child_prepare_to_store PARAMS ((void));
  32.  
  33. static int
  34. child_wait PARAMS ((int *));
  35.  
  36. static void
  37. child_open PARAMS ((char *, int));
  38.  
  39. static void
  40. child_files_info PARAMS ((struct target_ops *));
  41.  
  42. static void
  43. child_detach PARAMS ((char *, int));
  44.  
  45. /* Forward declaration */
  46. extern struct target_ops child_ops;
  47.  
  48. /* Wait for child to do something.  Return pid of child, or -1 in case
  49.    of error; store status through argument pointer STATUS.  */
  50.  
  51. static int
  52. child_wait (status)
  53.      int *status;
  54. {
  55.   int pid;
  56.  
  57.   do {
  58. #ifdef USE_PROC_FS
  59.     pid = proc_wait (status);
  60. #else
  61.     pid = wait (status);
  62. #endif
  63.     if (pid == -1)        /* No more children to wait for */
  64.       {
  65.     fprintf (stderr, "Child process unexpectedly missing.\n");
  66.     *status = 42;    /* Claim it exited with signal 42 */
  67.         return -1;
  68.       }
  69.   } while (pid != inferior_pid); /* Some other child died or stopped */
  70.   return pid;
  71. }
  72.  
  73.  
  74. /*
  75.  * child_detach()
  76.  * takes a program previously attached to and detaches it.
  77.  * The program resumes execution and will no longer stop
  78.  * on signals, etc.  We better not have left any breakpoints
  79.  * in the program or it'll die when it hits one.  For this
  80.  * to work, it may be necessary for the process to have been
  81.  * previously attached.  It *might* work if the program was
  82.  * started via the normal ptrace (PTRACE_TRACEME).
  83.  */
  84.  
  85. static void
  86. child_detach (args, from_tty)
  87.      char *args;
  88.      int from_tty;
  89. {
  90.   int siggnal = 0;
  91.  
  92. #ifdef ATTACH_DETACH
  93.   if (from_tty)
  94.     {
  95.       char *exec_file = get_exec_file (0);
  96.       if (exec_file == 0)
  97.     exec_file = "";
  98.       printf ("Detaching program: %s pid %d\n",
  99.           exec_file, inferior_pid);
  100.       fflush (stdout);
  101.     }
  102.   if (args)
  103.     siggnal = atoi (args);
  104.   
  105.   detach (siggnal);
  106.   inferior_pid = 0;
  107.   unpush_target (&child_ops);        /* Pop out of handling an inferior */
  108. #else
  109.     error ("This version of Unix does not support detaching a process.");
  110. #endif
  111. }
  112.  
  113. /* Get ready to modify the registers array.  On machines which store
  114.    individual registers, this doesn't need to do anything.  On machines
  115.    which store all the registers in one fell swoop, this makes sure
  116.    that registers contains all the registers from the program being
  117.    debugged.  */
  118.  
  119. static void
  120. child_prepare_to_store ()
  121. {
  122. #ifdef CHILD_PREPARE_TO_STORE
  123.   CHILD_PREPARE_TO_STORE ();
  124. #endif
  125. }
  126.  
  127. /* Convert data from raw format for register REGNUM
  128.    to virtual format for register REGNUM.  */
  129.  
  130. /* Some machines won't need to use regnum.  */
  131. /* ARGSUSED */
  132. void
  133. host_convert_to_virtual (regnum, from, to)
  134.      int regnum;
  135.      char *from;
  136.      char *to;
  137. {
  138.   REGISTER_CONVERT_TO_VIRTUAL (regnum, from, to);
  139. }
  140.  
  141. /* Convert data from virtual format for register REGNUM
  142.    to raw format for register REGNUM.  */
  143.  
  144. /* ARGSUSED */
  145. void
  146. host_convert_from_virtual (regnum, from, to)
  147.      int regnum;
  148.      char *from;
  149.      char *to;
  150. {
  151.   REGISTER_CONVERT_TO_RAW (regnum, from, to);
  152. }
  153.  
  154. /* Print status information about what we're accessing.  */
  155.  
  156. static void
  157. child_files_info (ignore)
  158.      struct target_ops *ignore;
  159. {
  160.   printf ("\tUsing the running image of %s process %d.\n",
  161.       attach_flag? "attached": "child", inferior_pid);
  162. }
  163.  
  164. /* ARGSUSED */
  165. static void
  166. child_open (arg, from_tty)
  167.      char *arg;
  168.      int from_tty;
  169. {
  170.   error ("Use the \"run\" command to start a Unix child process.");
  171. }
  172.  
  173. struct target_ops child_ops = {
  174.   "child",            /* to_shortname */
  175.   "Unix child process",        /* to_longname */
  176.   "Unix child process (started by the \"run\" command).",    /* to_doc */
  177.   child_open,            /* to_open */
  178.   0,                /* to_close */
  179.   child_attach,            /* to_attach */
  180.   child_detach,         /* to_detach */
  181.   child_resume,            /* to_resume */
  182.   child_wait,            /* to_wait */
  183.   fetch_inferior_registers,    /* to_fetch_registers */
  184.   store_inferior_registers,    /* to_store_registers */
  185.   child_prepare_to_store,    /* to_prepare_to_store */
  186.   host_convert_to_virtual,    /* to_convert_to_virtual */
  187.   host_convert_from_virtual,    /* to_convert_from_virtual */
  188.   child_xfer_memory,        /* to_xfer_memory */
  189.   child_files_info,        /* to_files_info */
  190.   memory_insert_breakpoint,    /* to_insert_breakpoint */
  191.   memory_remove_breakpoint,    /* to_remove_breakpoint */
  192.   terminal_init_inferior,    /* to_terminal_init */
  193.   terminal_inferior,         /* to_terminal_inferior */
  194.   terminal_ours_for_output,    /* to_terminal_ours_for_output */
  195.   terminal_ours,        /* to_terminal_ours */
  196.   child_terminal_info,        /* to_terminal_info */
  197.   kill_inferior,        /* to_kill */
  198.   0,                /* to_load */
  199.   0,                /* to_lookup_symbol */
  200.   child_create_inferior,    /* to_create_inferior */
  201.   child_mourn_inferior,        /* to_mourn_inferior */
  202.   process_stratum,        /* to_stratum */
  203.   0,                /* to_next */
  204.   1,                /* to_has_all_memory */
  205.   1,                /* to_has_memory */
  206.   1,                /* to_has_stack */
  207.   1,                /* to_has_registers */
  208.   1,                /* to_has_execution */
  209.   0,                /* sections */
  210.   0,                /* sections_end */
  211.   OPS_MAGIC            /* to_magic */
  212. };
  213.  
  214. void
  215. _initialize_inftarg ()
  216. {
  217.   add_target (&child_ops);
  218. }
  219.